package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.ApiResponse
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.requestNoCheck
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.homeService
import com.polaris.live.net.userService
import com.polaris.live.resp.back_resp.DisplayUserBean
import com.polaris.live.resp.back_resp.InfoOtherResp
import com.polaris.live.resp.go_resp.OtherUserIdBean
import com.polaris.live.utils.BitwiseUtils

/**
 * SpectatorEndViewModel
 *
 * @author Created by 半仙 on 2023/10/9/009 15:46
 */
class SpectatorEndViewModel : BaseViewModel() {

    //获取用户基础信息
    val userBasisLiveData = MutableLiveData<ResultState<InfoOtherResp>>()
    fun getBasisInfoUser(id: Long) {
        val type = BitwiseUtils.bitwiseOperation(
            longArrayOf(
                UserManager.BASIC_INFORMATION,
                UserManager.RELATIONSHIP_INFORMATION,
                UserManager.DECORATIVE_DISPLAY
            )
        )
        request({ userService.getInfoOther(id, type) }, userBasisLiveData)
    }

    //关注
    val followerLiveData = MutableLiveData<ResultState<Any>>()
    fun addFollower(otherId: Long) {
        requestLoading({ userService.addFollower(OtherUserIdBean(otherId)) }, followerLiveData)
    }

    //获取结束页推荐数据
    val livesRecommendLiveData = MutableLiveData<ResultState<List<DisplayUserBean>>>()
    fun getLivesRecommend() {
        request({ homeService.getLivesRecommend() }, livesRecommendLiveData)
    }

    val liveLiveData = MutableLiveData<ResultState<ApiResponse<DisplayUserBean>>>()
    fun getLivesLive(pageNumber: Int, currentUserId: Long? = null) {
        requestNoCheck({ homeService.getLiveSingle(pageNumber, currentUserId) }, liveLiveData)
    }

    //获取结束页推荐数据  (派对)
    val partyRecommendLiveData = MutableLiveData<ResultState<List<DisplayUserBean>>>()
    fun getPartyRecommend() {
        request({ homeService.getPartyRecommend() }, partyRecommendLiveData)
    }

    //获取单个派对
    val liveLoadMoreLiveData = MutableLiveData<ResultState<ApiResponse<DisplayUserBean>>>()
    fun getLoadMore() {
        requestNoCheck({ homeService.getLiveParty() }, liveLoadMoreLiveData)
    }


    //获取结束页推荐数据  (游戏派对)
    val partyGameRecommendLiveData = MutableLiveData<ResultState<List<DisplayUserBean>>>()
    fun getGamePartyRecommend() {
        request({ homeService.getGamePartyRecommend() }, partyGameRecommendLiveData)
    }

    //获取单个游戏派对
    val gamePartyData = MutableLiveData<ResultState<ApiResponse<DisplayUserBean>>>()
    fun getGameParty() {
        requestNoCheck({ homeService.getLiveGame() }, gamePartyData)
    }
}